//
//  HWMineNavView.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/22.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWMineNavView: UIView {
    var items:[HWMineNavItemView] = Array()
    var buttons:[UIButton] = Array()
    var navClick:((_ model:HWMineNavModel)->())?
    var model:HWMineModel?{
        didSet {

            for v in items {
                v.removeFromSuperview()
            }
            items.removeAll()
            
            buttons.removeAll()
//            if model?.nav.count ?? 0 > 0 {
//                var tempView:HWMineNavItemView!
//                for i in 0..<(model?.nav.count ?? 0){
//                    let navItemView = HWMineNavItemView()
//                    navItemView.imageView.sd_setImage(with: URL(string: model?.nav[i].icon ?? ""), completed: nil)
//                    navItemView.nameLabel.text = model?.nav[i].name
//                    addSubview(navItemView)
//                    
//                    let button = UIButton(type: .custom)
//                    button.tag = i
//                    button.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
//                    navItemView.addSubview(button)
//                    
//                    if tempView == nil {
//                        navItemView.snp.makeConstraints { make in
//                            make.left.equalTo(0)
//                            make.top.equalTo(0)
//                            make.width.equalTo((screenWidth-40*widthScale)/4)
//                            make.height.equalTo(69*widthScale)
//                        }
//                    }else{
//                        if i % 4 == 0 {
//                            navItemView.snp.makeConstraints { make in
//                                make.left.equalTo(0)
//                                make.top.equalTo(tempView.snp.bottom)
//                                make.width.equalTo((screenWidth-40*widthScale)/4)
//                                make.height.equalTo(69*widthScale)
//                            }
//                        }else{
//                            navItemView.snp.makeConstraints { make in
//                                make.left.equalTo(tempView.snp.right)
//                                make.top.equalTo(tempView)
//                                make.width.equalTo((screenWidth-40*widthScale)/4)
//                                make.height.equalTo(69*widthScale)
//                            }
//                        }
//                    }
//                    tempView = navItemView
//                    if i == (model?.nav.count ?? 0) - 1 {
//                        navItemView.snp.makeConstraints { make in
//                            make.bottom.equalToSuperview()
//                        }
//                    }
//                    button.snp.makeConstraints { make in
//                        make.edges.equalToSuperview()
//                    }
//                    items.append(navItemView)
//                }
//            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
    }

}

extension HWMineNavView {
    private func initUI() -> Void {
        backgroundColor = .white
        layer.cornerRadius = 10*widthScale
        
        
        
    }
    
    private func initFrame() -> Void {
        
    }
}

extension HWMineNavView{
    @objc func buttonClick(_ button:UIButton) -> Void {
        self.navClick?(model!.nav[button.tag])
    }
}
